﻿Public MustInherit Class File

	Public Name As String
	Public Title As String
	Public Album As Album
	Public Item As ListViewItem
	Public BelongsTo As String
	Public Picture As Canvas
	Public Tags As New List(Of String)
	Public DateTaken As String

	MustOverride Sub Draw(ByVal G As Graphics, ByVal R As Rectangle, ByVal IsSelected As Boolean, ByVal IsHot As Boolean, ByVal IsFocused As Boolean, ByVal IsDropTarget As Boolean)

	Sub Redraw()
		If Not Picture Is Nothing Then If Picture.Visible Then Picture.FixRect()
		If Item Is Nothing OrElse Item.ListView Is Nothing Then Exit Sub
		Item.ListView.Invalidate(Item.Bounds)
	End Sub

	Overridable Sub Parse(ByVal Item As String)
	End Sub

	Property Selected As Boolean
		Get
			Return Item.Selected
		End Get
		Set(ByVal Value As Boolean)
			Item.Selected = Value
		End Set
	End Property

	Overridable Function Text() As String
		Dim S As String = ""
		S &= vbTab & "type=" & TypeName(Me)
		S &= vbTab & "name=" & Name
		S &= vbTab & "title=" & Title
		S &= vbTab & "album=" & If(Album Is Nothing, "", Album.Name)
		S &= vbTab & "tags=" & Join(Tags.ToArray, ";")
		Return S
	End Function

	MustOverride Sub SaveXML(ByVal Doc As Xml.XmlTextWriter)
	MustOverride Sub SaveDB()

	Sub SaveAsXML(ByVal Doc As Xml.XmlTextWriter)
		Doc.WriteStartElement(TypeName(Me))
		Doc.WriteAttributeString("title", Title)
		SaveXML(Doc)
		Doc.WriteEndElement()
	End Sub

	Public ID As Integer
	Sub SaveDB(ByVal Parent As Integer)
		ExecSQL("insert into items (name,parent) values (@name,@parent)", Title, Parent)
		ID = OpenSQL("select max(id) from items")(0)
		SaveDB()
	End Sub

	Function Path() As String
		Return If(Album Is Nothing, "Tüm albümler", Album.Path & "\" & Title)
	End Function

	Function Source() As String
		Return MainFolder & Title
	End Function

	Sub Populate(ByVal Node As TreeNode)
		Node.Text = Title
		Node.Tag = Me
		Node.Name = Name
		Node.ImageKey = "album"
	End Sub

	Sub Populate(ByVal Item As ListViewItem)
		Me.Item = Item
		Item.Name = Name
		Item.Tag = Me
		Item.Text = Title
		Item.SubItems.Add(DateTaken)
		Item.SubItems.Add(Mid(DateTaken, 1, 10))
		Item.SubItems.Add(Mid(DateTaken, 1, 7))
		Item.SubItems.Add(Mid(DateTaken, 1, 4))
		If TypeOf Me Is Album Then
			Item.ImageKey = "album"
		ElseIf TypeOf Me Is Photo Then
			Item.ImageKey = "photo"
		ElseIf TypeOf Me Is Video Then
			Item.ImageKey = "video"
		End If
		Me.Item = Item
	End Sub

   Sub Destroy()
      'Studio.Files.Remove(Name)
   End Sub

	ReadOnly Property IsCut As Boolean
		Get
			'Return Studio.Clipboard.Contains(Me)
			Return False
		End Get
	End Property

	ReadOnly Property Index As Integer
		Get
			Return Item.Index
		End Get
	End Property

	Sub EnsureVisible()
		Item.EnsureVisible()
	End Sub

	Dim m_Size As String
	Property Size As String
		Get
			Return m_Size
		End Get
		Set(ByVal Value As String)
			m_Size = Value
			Dim Items = Value.Split("x")
			m_Width = Items(0)
			m_Height = Items(1)
		End Set
	End Property

	Dim m_Width As Integer = 0
	ReadOnly Property Width As Integer
		Get
			Return m_Width
		End Get
	End Property

	Dim m_Height As Integer = 0
	ReadOnly Property Height As Integer
		Get
			Return m_Height
		End Get
	End Property

End Class